#pragma once

#include "IFTPClient.h"
#include "singletonTemplate.h"
#include "IFtpNotifier.h"
#include "ThinWorkerThread.h"
#include "MyQueue.h"
#include "PerformanceClass.h"

enum FTP_COMM
{
	DOWN_LOAD = 0,
	UP_LOAD
};
typedef 
struct tagFtpInfo
{
	FTP_COMM cmdtype;
	CString strRemotePath;
	CString strLocalPath;
} FTPINFO,*PFTPINFO;
//class IFtpNotifier;
typedef IFTPClient* (*LPGetFTPClient)(IFTPClientNotify* pNotify,ISysLog* pSysLog ,int index );
typedef void (*LPReleaseFTPClient)(IFTPClient* pFTPClient);
class CFtp:
	public IFTPClientNotify,
	public CThinWorkerThread,
	public IFtpNotifier
{
	friend class CSingleton<CFtp>;

protected:

	CFtp();
	virtual ~CFtp();

public:
	virtual bool Initialize(TCHAR* pHost, TCHAR* pUser, TCHAR* pPwd, UINT32 nPort, UINT32 nIndex);
	virtual bool MakeDirectory(TCHAR strDirectory[MAX_PATH]);
	virtual bool IsFileExist(TCHAR strFilePath[MAX_PATH]);
	virtual bool UploadFile(TCHAR szLocalFile[MAX_PATH], TCHAR szRemoteFile[MAX_PATH]);
	virtual bool DownloadFile(TCHAR szRemoteFile[MAX_PATH], TCHAR szLocalFile[MAX_PATH],int iTimeOut = 0);
	virtual bool Login();
	virtual bool Logout();
	virtual bool IsConnected();
	virtual bool DisConnect(){return true;};
	virtual bool ReCreateConnect(){return true;};
	void OnConnected(bool bConnected);

	bool NotifyFtpStatus(DWORD dwStatus, DWORD dwParam1 = 0, DWORD dwParam2 = 0);

	void	SendCommond(const FTPINFO& info);
	void	ClearCommond();

protected:

	DWORD	ThreadMemberFunc();
	bool	ProcCommand();



protected:

	ftp_login_info m_ftpInfo;
	IFTPClient* m_pIFTPClient;
	TCHAR m_cUser[MAX_FTP_USER_NAME];
	UINT32 m_nFtpIndex;
	IFtpNotifier* m_pIFtpNotifier;
	bool m_bConnected;

	HMODULE m_hModule;
	LPGetFTPClient m_pGetFTPClient;
	LPReleaseFTPClient m_pReleaseFTPClient;

	MyQueue<FTPINFO>	m_CmdQue;

};

